﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraMana : MonoBehaviour
{
    [SerializeField] private Transform targetObj;

    [SerializeField] private Transform targetCam;
    [SerializeField] private Vector3 cameraFreelookRotation;

    [SerializeField] public bool isAnimation = true, isFree;

    [SerializeField] private Vector3 scrollSpeedXYZ;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (isAnimation)
        {
            startAnimationFollow();
        }
        else if (isFree)
        {
            isOnFreelook();
        }

    }

    void startAnimationFollow()
    {
        targetCam.LookAt(targetObj);
    }

    void isOnFreelook()
    {
        targetCam.localRotation = Quaternion.Euler(cameraFreelookRotation);
        Vector2 mousePos = new Vector2(Input.GetAxis("Mouse X"),Input.GetAxis("Mouse Y"));
        float mouseScroll = Input.GetAxis("Mouse ScrollWheel");
        if (Input.GetMouseButton(2))
        {
            targetCam.position += targetCam.right * mousePos.x * scrollSpeedXYZ.x * -1;
            targetCam.position += targetCam.up * mousePos.y * scrollSpeedXYZ.y * -1;
        }
        //Debug.Log(mouseScroll);
        if (Input.GetAxis("Mouse ScrollWheel") != 0)
        {
            targetCam.position += -1 * targetCam.forward * mouseScroll * scrollSpeedXYZ.z;
        }
        //targetCam.LookAt(new Vector3(0,1,0));
    }
    
    
}
